package com.itheima.consumer.controller;

import com.itheima.consumer.domain.Goods;
import com.itheima.consumer.feign.GoodsFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
public class OrderController {
    
    @Autowired
    private RestTemplate restTemplate;
    
    @GetMapping("/goods1/{id}")
    public Goods findGoodsById1(@PathVariable("id") int id) {
        
        String url = "http://FEIGN-PROVIDER/goods/findOne/" + id;
        // 3. 调用方法
        Goods goods = restTemplate.getForObject(url, Goods.class);
        
        return goods;
    }
    
    @Autowired
    private GoodsFeignClient goodsFeignClient;
    
    @GetMapping("/goods/{id}")
    public Goods findGoodsById(@PathVariable("id") int id) {
        
        Goods goods = goodsFeignClient.findOne(id);
        
        return goods;
    }
    
}
